package org.jeecg.modules.helper;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.MsgResult;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.HttpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.Map;

@Component
@Slf4j
public class MessageHelp {
   @Value("${lankedi.url}")
   private String apiUrl;

    /**
     *蓝客帝服务发送短信验证码
     * */
    public MsgResult sendValidCode(Map<String,Object> params) {
        String url=apiUrl+"common/fxSendCode";

        String result =  HttpUtil.doPostJson(url,params);
        log.info("sendValidCode:{}",result);
        if(StringUtils.isNotEmpty(result)){
          return   JSONObject.parseObject(result,MsgResult.class);
        }

        return MsgResult.error("发送验证码失败");
    }

    /**
     *蓝客帝服务验证码校验
     * */
    public MsgResult<String> validCode(Map<String,Object> params) {
        String url=apiUrl+"common/fxValidCode";

        String result =  HttpUtil.doPostJson(url,params);
        log.info("validCode:{}",result);
        if(StringUtils.isNotEmpty(result)){
            return   JSONObject.parseObject(result,MsgResult.class);
        }
        return MsgResult.error("验证失败");
    }

    /**
     *注册蓝客帝服务用户
     * */
    public MsgResult<String> fxRegister(Map<String,Object> params) {
        String url=apiUrl+"user/fxRegister";

        String result =  HttpUtil.doPostJson(url,params);
        log.info("fxRegister:{}",result);
        if(StringUtils.isNotEmpty(result)){
            return   JSONObject.parseObject(result,MsgResult.class);
        }
        return MsgResult.error("注册失败");
    }

    /**
     *领取优惠券
     * */
    public MsgResult<String> addCoupon(Map<String,Object> params) {
        String url=apiUrl+"common/addCoupon";

        String result =  HttpUtil.doPostJson(url,params);
        log.info("addCoupon:{}",result);
        if(StringUtils.isNotEmpty(result)){
            return   JSONObject.parseObject(result,MsgResult.class);
        }
        return MsgResult.error("领取失败");
    }
}
